package com.example.spring.test.thread;

/**
 * Created by Administrator on 2017-8-10.
 */
public class Stage extends Thread{
    public void run(){
        System.out.println("欢迎来到草根儿大舞台，现在开始隋唐演义的战斗大戏！");
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println("大幕徐徐拉开！");
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println("话说隋朝末年，隋军与农民起义军杀得昏天黑地...");
        ArmyThread suiArmy = new ArmyThread();
        ArmyThread nongArmy = new ArmyThread();
        Thread suiArmyThread = new Thread(suiArmy,"杨广领导的隋军");
        Thread nongArmyThread = new Thread(nongArmy,"农民起义军");

        //两军开始厮杀
        suiArmyThread.start();
        nongArmyThread.start();

        //让观众看一会战场
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println("正当双方激战正酣，突然一声：“俺程咬金来也！”，原来半路杀出了个程咬金...");
        Thread chengyjThread = new KeyPersonThread();
        chengyjThread.setName("大将军程咬金");
        System.out.println("程咬金的理想就是结束战争，使百姓安居乐业！");

        //结束两军交战
        suiArmy.keepRunning = false;
        nongArmy.keepRunning = false;

        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        //程将军开始登场
        chengyjThread.start();

        try {
            chengyjThread.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println("战争结束，人民安居乐业，程先生实现了积极的人生梦想，为人民作出了贡献！");
        System.out.println("谢谢观看隋唐演义，再见！");

    }

    public static void main(String[] args) {
        new Stage().start();
    }

}
